#include "qdatapanelwidget.h"

#include "qdatapanel.h"

#include "../styledbar.h"
#include "../minisplitter.h"

#include <QVBoxLayout>
#include <QSqlQuery>

QDataPanelWidget::QDataPanelWidget(QWidget *parent) :
    QWidget(parent),
    m_splitter(new MiniSplitter),
    m_point(0)
{
    QVBoxLayout *v=new QVBoxLayout;
    v->setMargin(0);
    v->setSpacing(0);
    v->addWidget(m_splitter);

    setLayout(v);
    for(int i=0;i<2;i++)
    {
        QDataPanel *panel=new QDataPanel;

        m_splitter->addWidget(panel);
        m_panels.append(panel);
    }
}

QDataPanelWidget::~QDataPanelWidget()
{
}

void QDataPanelWidget::set_query(QSqlQuery *query)
{
    QDataPanel* panel=NULL;
    query->first();
    QString str=query->value(1).toString()+"."+query->value(0).toString();

    foreach(QDataPanel *p,m_panels)
    {
        if(p->text()==str)
        {
            return;
        }
    }
    panel=m_panels.at(m_point);
    panel->set_query(query);
    panel->set_text(str);
    if(m_point==0)
    {
        m_point=1;
    }
    else
    {
        m_point=0;
    }
}

void QDataPanelWidget::clear()
{
    foreach(QDataPanel *p,m_panels)
    {
        p->clear();
    }
}
